<%--
    Document   : courierDboardMain
    Created on : Apr 20, 2013, 1:39:21 PM
    Author     : Andriy
--%>

<%@page import="entity.Users"%>
<%@page import="entity.Orders"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<script language="Javascript">
    function viewOrderDetail(){       
        document.getElementById("dashboard").value="2";
        document.getElementById("Detail").action="getOrderDetail";     
        document.getElementById("Detail").submit();        
    }
    function nextPage() {
        document.getElementById("page").value =<%=(Integer) request.getAttribute("page") + 1%>;
        document.getElementById("pagingForm").action = "WarehouseOrders";
        document.getElementById("pagingForm").submit();
    }
    function prevPage() {
        document.getElementById("page").value =<%=(Integer) request.getAttribute("page") - 1%>;
        document.getElementById("pagingForm").action = "WarehouseOrders";
        document.getElementById("pagingForm").submit();
    }
    function jumpToPage() {
        document.getElementById("pagingForm").action = "WarehouseOrders";
        document.getElementById("pagingForm").submit();
    }
</script>
<!DOCTYPE html>
<%
    Users user = (Users) session.getAttribute("user");
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/warehouse.css">
        <link rel="stylesheet" type="text/css" href="css/all.css">
        <title>Warehouse Dashboard</title>
    </head>
    <body>
        <header>
            <div id ="top_name"> <a href="main.jsp"> 
                    <img src="/Delta-war/product/1.jpeg"></a>
                <h1> Warehouse Dashboard</h1> </div>
             
            <div id="registr2">
                <p> <a href="user_name.jsp"><%=user.getLogin()%></a>
                                    <a href="logout">LogOut</a> </p>
            </div>
            <div id="menu">

                <div id="line" style="background: #ff0000; "> <a href="WarehouseOrders"> Orders</a> </div>
                <div id="line"> <a href="ViewWarehouse"> Warehouses</a> </div>
                <div id="line" > <a href="catalog_product.jsp"> Product</a> </div>
             
            </div>
                
            </div>
             <div id="user-panel">
                   <%@ include file="rolefragment.jsp" %> 
        </div>
        </header>

        <div id="main2">

            <div id="sorted1">

                <%String sort = "";
                if (request.getAttribute("sort") != null) {
                    sort = (String) request.getAttribute("sort");
                }%>
            <%String by = "";
                if (request.getAttribute("by") != null) {
                    by = (String) request.getAttribute("by");
                }%>
                <form action="WarehouseOrders" method="GET" name="drop_down_box">
                    <select name="sort" size="1">
                        <option <%if (sort.equalsIgnoreCase("IdOrder")) {%>selected<%}%> value="IdOrder">#Order</option>
                        <option  <%if (sort.equalsIgnoreCase("orderDate")) {%>selected<%}%> value="orderDate">Order Date</option>
                        <option <%if (sort.equalsIgnoreCase("idWarehouse")) {%>selected<%}%> value="idWarehouse">Warehouse</option>
                        <option <%if (sort.equalsIgnoreCase("address")) {%>selected<%}%> value="address">Address</option>
                        <option <%if (sort.equalsIgnoreCase("shippingPrice")) {%>selected<%}%> value="shippingPrice">Shipping price</option>
                        <option <%if (sort.equalsIgnoreCase("productPrice")) {%>selected<%}%> value="productPrice">Product price</option>
                    </select>
                    <select name="by" size="1">
                        <option <%if (by.equalsIgnoreCase("asc")) {%>selected<%}%> value="asc">asc</option>
                        <option  <%if (by.equalsIgnoreCase("desc")) {%>selected<%}%> value="desc">desc</option>
                    </select>
                    <input type="submit" value="Sort" style="background: #b8b0fd;"/> 
                </form></div>
                    <br>
            <ul>
                <li><a href="WarehouseOrders?status=queued">Only queued orders</a></li>
                <li><a href="WarehouseOrders?status=canceled">Only canceled orders</a></li>
            </ul>
            <div id="tabl1" >
                <p>Orders:</p>
                <table width="90%">

                    <TR>
                        <td id="head_table_first" >Order #</td>
                        <td id="head_table_first">Order Date </td>
                        <td id="head_table_first">  Order Status</td>
                        <td id="head_table_first">Warehouse </td>
                        <td id="head_table_first">Address </td>
                        <td id="head_table_first">  Shipping price</td>
                        <td id="head_table_first">  Product price</td>
                        <td id="head_table_first">Detail</td>
                    </TR>

                    <% List<Orders> ordersList = (List) request.getAttribute("ordersList");
                        for (Iterator<Orders> itr = ordersList.iterator(); itr.hasNext();) {
                            Orders o = itr.next();%>
                    <TR>
                        <td id="colomn_first" > <%=o.getTrackingNumber()%></td>   
                        <td id="colomn_first" > <%=o.getOrderDate()%></td>  
                        <td id="colomn_first" > <%=o.getOrderStatus()%></td> 
                        <td id="colomn_first" > <%=o.getIdWarehouse().getName()%></td> 
                        <td id="colomn_first" > <%=o.getAddress()%></td>
                        <td id="colomn_first" > <%=o.getShippingPrice()%></td>
                        <td id="colomn_first" > <%=o.getProductPrice()%></td>
                        <td id="colomn_first">
                            <form method="POST" action="getOrderDetail">
                                <input type="hidden" name="idOrder" value="<%=o.getIdOrder()%>"/>
                                <input type="hidden"  id="dashboard" name="dashboard" value="2"/>
                                <button  onclick="viewOrderDetail()">Detail</button> 
                            </form>
                        </td>
                    </TR>
                    <%}%>
                </table> 
                <%int pageNum = (Integer) request.getAttribute("count");%>
                <% int currentPage = (Integer) request.getAttribute("page");%>
                <form id="pagingForm" method="GET" action="jumpToPage();">                 
                    <div id="line_button"> 
                        <button 
                            id="navigation" 

                            onclick="prevPage();" <%= currentPage > 1 ? "" : "disabled"%>> 
                            << 
                        </button></div>
                    <input type="hidden"  name="status"  value="<%=request.getAttribute("status")%>"/>
                    <input type="hidden"  name="sort"  value="<%=request.getAttribute("sort")%>"/>
                    <input type="hidden"  name="by"  value="<%=request.getAttribute("by")%>"/>
                    <div id="line_button"> <%=currentPage%> of <%=pageNum%>

                        <button 
                            id="navigation" 
                            onclick="nextPage();" <%= currentPage < pageNum ? "" : "disabled"%> > 
                            >> 
                        </button>
                    </div>
                    <div id="line_button"><input  name="page" id="page" size="1"  value="<%=currentPage%>"/>
                    <button 
                            id="navigation" 
                            onclick="jumpToPage();"  >
                            Go to
                        </button></div>

                </form>
            </div>

        </div>
        <%if (request.getAttribute("success") != null) {%>
        <script type=text/javascript>
                    alert("<%=request.getAttribute("success")%>");
        </script>
        <%}%>
        <div id="footer">
                                <p>  &#169;All rights reserved</p>
                            </div>
    </body>
</html>
